package com.wf.course.web.controller.comm;


import java.util.HashMap;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import com.utils.page.PageBean;
import com.wf.course.model.comm.Area;
import com.wf.course.service.IAreaService;
import com.wf.course.web.Interceptor.LogInfo;

/**
 *区域信息管理
 */
@RequestMapping("area")
@Controller
public class AreaController {

	@Autowired
	private IAreaService areaService;

	
	 /***
	  * 区域信息管理
	  * @param pageNo
	  * @param pageSize
	  * @param title
	  * @param model
	  * @return
	  */
	@LogInfo("查询区域信息列表")
	@RequestMapping("areaList")
	public String areaList(@RequestParam(value = "pageNo", required = false) Integer pageNo,
						  @RequestParam(value = "pageSize", required = false) Integer pageSize,
						  @RequestParam(value = "provinceName", required = false) String provinceName,
						  @RequestParam(value = "cityName", required = false) String cityName,
						  Model model){
		Map<String,Object> map=new HashMap<String,Object>(); 
		map.put("provinceName",provinceName);
		map.put("cityName",cityName);
		
		PageBean<Area> pageBean = new PageBean<Area>(pageNo, pageSize,null,map);
		
		areaService.getAreasList(pageBean);
		pageBean.setUrl("/area/areaList");
		model.addAttribute("page", pageBean);
		
		return "comm/areaList";
	}
	
	/**
	 * 区域信息：新增修改页面信息加载
	 * @param id
	 * @return
	 */
	@LogInfo("新增/修改区域信息，页面数据初始化")
	@RequestMapping("downLoadarea/{id}")
	public String downLoadarea(@PathVariable("id") Integer id,Model model){
		 if(id!=null && id!=0){
			 Area area = this.areaService.downLoadArea(id);
				model.addAttribute("area", area);
				model.addAttribute("type", "upd");
		 }else{
			 model.addAttribute("type", "add");
		 }
		 
		return "comm/areaEdit";		
	}
	
	
	/**
	 * 添加或修改
	 * @param eval
	 * @param logoFile
	 * @param newsFile
	 * @param request
	 * @return
	 */
	@LogInfo("新增/修改区域信息")
	@RequestMapping(value = {"areaEdit" } )
	public String areaEdit(@ModelAttribute Area area, 
 			HttpServletRequest request){
		 
			//添加信息区域信息
			if(area.getId()==null){				 
				//保存
				areaService.saveArea(area);
			}else{
				//修改			
				areaService.updateArea(area);				
			}		 
		 
		return "redirect:/area/areaList";
		
	}
	
	/**
	 * 删除区域信息
	 * @param id
	 * @return
	 */
	@LogInfo("删除区域信息")
	@RequestMapping(value="deletearea/{id}"  )
	public String deletearea(@PathVariable Integer id){
			this.areaService.deleteArea(id);
			
			return "redirect:/area/areaList";
	}
	
}
